package com.android.jr_infraredcamera

import android.Manifest
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import com.tbruyelle.rxpermissions3.RxPermissions

class SplashActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)

        val rxPermissions = RxPermissions(this) // where this is an Activity or Fragment instance
        rxPermissions.request(
            Manifest.permission.RECORD_AUDIO,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.CALL_PHONE,
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.CAMERA,
        ).subscribe { granted: Boolean ->
            if (granted) {
                window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
                Handler(Looper.getMainLooper()).postDelayed({
                    Intent(this, MainActivity::class.java).apply {
                        startActivity(this)
                        finish()
                    }
                }, 800)
            } else {
                finish()
            }
        }
    }
}